package com.internal.Internalhibernate.server;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * 
 * @author Ruba
 */
public class SessionFactoryUtil {
	private static SessionFactory sessionFactory;

	private SessionFactoryUtil() {
	}

	static {
		try {
			sessionFactory = new Configuration().configure(
					"com/internal/Internalhibernate/server/hibernate.cfg.xml").buildSessionFactory();
		} catch (Throwable ex) {
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * closes the session factory
	 */
	public static void close() {
		if (sessionFactory != null)
			sessionFactory.close();
		sessionFactory = null;
	}
}
